package jmetal.problems.adaboost;

public class Feature2 extends Feature {

	public Feature2()
	{
		setType(2);
		setMinHeight(2);
		setMinWidth(1);
	}
	@Override
	public double calculateValue(double[][] image, int x, int y, int width, int height) {
		double result = 0;
		double A1, B1, C1, D1, A2, B2, C2, D2;
		if (x == 0) {
			A1 = B1 = A2 = B2 = 0;
			if (y == 0)
				C1 = 0;
			else {
				C1 = image[x - 1 + (width)][y - 1];
			}
		} else if (y == 0) {
			A1 = C1 = 0;
			B1 = image[x - 1][y - 1 + (height / 2)];
			A2 = B1;
			B2 = image[x - 1][y - 1 + height];
		} else {
			B1 = image[x - 1][y - 1 + (height / 2)];
			A1 = image[x - 1][y - 1];
			C1 = image[x - 1 + (width)][y - 1];
			A2 = B1;
			B2 = image[x - 1][y - 1 + height];
		}

		D1 = image[x - 1 + width][y - 1 + (height / 2)];
		D2 = image[x - 1 + width][y - 1 + height];
		C2 = D1;
		double preto = A1 + D1 - (B1 + C1);
		double branco = A2 + D2 - (B2 + C2);
		result = preto - branco;
		setValue(result);
		return result;
	}

}
